home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PCGPEV10.ZIP / BMP.TXT < prev    next >
Text File  |  1994-05-10  |  41KB  |  1,035 lines

  1. Graphics File Formats
  2.  
  3. This topic describes the graphics-file formats used by the Microsoft Windows
  4. operating system. Graphics files include bitmap files, icon-resource files,
  5. and cursor-resource files.
  6.  
  7. Bitmap-File Formats
  8.  
  9. Windows bitmap files are stored in a device-independent bitmap (DIB) format
  10. that allows Windows to display the bitmap on any type of display device. The
  11. term "device independent" means that the bitmap specifies pixel color in a
  12. form independent of the method used by a display to represent color. The
  13. default filename extension of a Windows DIB file is .BMP.
  14.  
  15. Bitmap-File Structures
  16.  
  17. Each bitmap file contains a bitmap-file header, a bitmap-information header,
  18. a color table, and an array of bytes that defines the bitmap bits. The file
  19. has the following form:
  20.  
  21. BITMAPFILEHEADER bmfh;
  22. BITMAPINFOHEADER bmih;
  23. RGBQUAD          aColors[];
  24. BYTE             aBitmapBits[];
  25.  
  26. The bitmap-file header contains information about the type, size, and layout
  27. of a device-independent bitmap file. The header is defined as a
  28. BITMAPFILEHEADER structure.
  29.  
  30. The bitmap-information header, defined as a BITMAPINFOHEADER structure,
  31. specifies the dimensions, compression type, and color format for the bitmap.
  32.  
  33. The color table, defined as an array of RGBQUAD structures, contains as many
  34. elements as there are colors in the bitmap. The color table is not present
  35. for bitmaps with 24 color bits because each pixel is represented by 24-bit
  36. red-green-blue (RGB) values in the actual bitmap data area. The colors in the
  37. table should appear in order of importance. This helps a display driver
  38. render a bitmap on a device that cannot display as many colors as there are
  39. in the bitmap. If the DIB is in Windows version 3.0 or later format, the
  40. driver can use the biClrImportant member of the BITMAPINFOHEADER structure to
  41. determine which colors are important.
  42.  
  43. The BITMAPINFO structure can be used to represent a combined
  44. bitmap-information header and color table.  The bitmap bits, immediately
  45. following the color table, consist of an array of BYTE values representing
  46. consecutive rows, or "scan lines," of the bitmap. Each scan line consists of
  47. consecutive bytes representing the pixels in the scan line, in left-to-right
  48. order. The number of bytes representing a scan line depends on the color
  49. format and the width, in pixels, of the bitmap. If necessary, a scan line
  50. must be zero-padded to end on a 32-bit boundary. However, segment boundaries
  51. can appear anywhere in the bitmap. The scan lines in the bitmap are stored
  52. from bottom up. This means that the first byte in the array represents the
  53. pixels in the lower-left corner of the bitmap and the last byte represents
  54. the pixels in the upper-right corner.
  55.  
  56. The biBitCount member of the BITMAPINFOHEADER structure determines the number
  57. of bits that define each pixel and the maximum number of colors in the
  58. bitmap. These members can have any of the following values:
  59.  
  60. Value   Meaning
  61.  
  62. 1       Bitmap is monochrome and the color table contains two entries. Each
  63. bit in the bitmap array represents a pixel. If the bit is clear, the pixel is
  64. displayed with the color of the first entry in the color table. If the bit is
  65. set, the pixel has the color of the second entry in the table.
  66.  
  67. 4       Bitmap has a maximum of 16 colors. Each pixel in the bitmap is
  68. represented by a 4-bit index into the color table. For example, if the first
  69. byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel
  70. contains the color in the second table entry, and the second pixel contains
  71. the color in the sixteenth table entry.
  72.  
  73. 8       Bitmap has a maximum of 256 colors. Each pixel in the bitmap is
  74. represented by a 1-byte index into the color table. For example, if the first
  75. byte in the bitmap is 0x1F, the first pixel has the color of the
  76. thirty-second table entry.
  77.  
  78. 24      Bitmap has a maximum of 2^24 colors. The bmiColors (or bmciColors)
  79. member is NULL, and each 3-byte sequence in the bitmap array represents the
  80. relative intensities of red, green, and blue, respectively, for a pixel.
  81.  
  82. The biClrUsed member of the BITMAPINFOHEADER structure specifies the number
  83. of color indexes in the color table actually used by the bitmap. If the
  84. biClrUsed member is set to zero, the bitmap uses the maximum number of colors
  85. corresponding to the value of the biBitCount member.  An alternative form of
  86. bitmap file uses the BITMAPCOREINFO, BITMAPCOREHEADER, and RGBTRIPLE
  87. structures.
  88.  
  89. Bitmap Compression
  90.  
  91. Windows versions 3.0 and later support run-length encoded (RLE) formats for
  92. compressing bitmaps that use 4 bits per pixel and 8 bits per pixel.
  93. Compression reduces the disk and memory storage required for a bitmap.
  94.  
  95. Compression of 8-Bits-per-Pixel Bitmaps
  96.  
  97. When the biCompression member of the BITMAPINFOHEADER structure is set to
  98. BI_RLE8, the DIB is compressed using a run-length encoded format for a
  99. 256-color bitmap. This format uses two modes: encoded mode and absolute mode.
  100. Both modes can occur anywhere throughout a single bitmap.
  101.  
  102. Encoded Mode
  103.  
  104. A unit of information in encoded mode consists of two bytes. The first byte
  105. specifies the number of consecutive pixels to be drawn using the color index
  106. contained in the second byte.  The first byte of the pair can be set to zero
  107. to indicate an escape that denotes the end of a line, the end of the bitmap,
  108. or a delta. The interpretation of the escape depends on the value of the
  109. second byte of the pair, which must be in the range 0x00 through 0x02.
  110. Following are the meanings of the escape values that can be used in the
  111. second byte:
  112.  
  113. Second byte     Meaning
  114.  
  115. 0       End of line. 
  116. 1       End of bitmap. 
  117. 2       Delta. The two bytes following the escape contain unsigned values
  118. indicating the horizontal and vertical offsets of the next pixel from the
  119. current position.
  120.  
  121. Absolute Mode
  122.  
  123. Absolute mode is signaled by the first byte in the pair being set to zero and
  124. the second byte to a value between 0x03 and 0xFF. The second byte represents
  125. the number of bytes that follow, each of which contains the color index of a
  126. single pixel. Each run must be aligned on a word boundary.  Following is an
  127. example of an 8-bit RLE bitmap (the two-digit hexadecimal values in the
  128. second column represent a color index for a single pixel):
  129.  
  130. Compressed data         Expanded data
  131.  
  132. 03 04                   04 04 04 
  133. 05 06                   06 06 06 06 06 
  134. 00 03 45 56 67 00       45 56 67 
  135. 02 78                   78 78 
  136. 00 02 05 01             Move 5 right and 1 down 
  137. 02 78                   78 78 
  138. 00 00                   End of line 
  139. 09 1E                   1E 1E 1E 1E 1E 1E 1E 1E 1E 
  140. 00 01                   End of RLE bitmap 
  141.  
  142. Compression of 4-Bits-per-Pixel Bitmaps
  143.  
  144. When the biCompression member of the BITMAPINFOHEADER structure is set to
  145. BI_RLE4, the DIB is compressed using a run-length encoded format for a
  146. 16-color bitmap. This format uses two modes: encoded mode and absolute mode.
  147.  
  148. Encoded Mode
  149.  
  150. A unit of information in encoded mode consists of two bytes. The first byte
  151. of the pair contains the number of pixels to be drawn using the color indexes
  152. in the second byte.
  153.  
  154. The second byte contains two color indexes, one in its high-order nibble
  155. (that is, its low-order 4 bits) and one in its low-order nibble.
  156.  
  157. The first pixel is drawn using the color specified by the high-order nibble,
  158. the second is drawn using the color in the low-order nibble, the third is
  159. drawn with the color in the high-order nibble, and so on, until all the
  160. pixels specified by the first byte have been drawn.
  161.  
  162. The first byte of the pair can be set to zero to indicate an escape that
  163. denotes the end of a line, the end of the bitmap, or a delta. The
  164. interpretation of the escape depends on the value of the second byte of the
  165. pair. In encoded mode, the second byte has a value in the range 0x00 through
  166. 0x02. The meaning of these values is the same as for a DIB with 8 bits per
  167. pixel.
  168.  
  169. Absolute Mode
  170.  
  171. In absolute mode, the first byte contains zero, the second byte contains the
  172. number of color indexes that follow, and subsequent bytes contain color
  173. indexes in their high- and low-order nibbles, one color index for each pixel.
  174. Each run must be aligned on a word boundary.
  175.  
  176. Following is an example of a 4-bit RLE bitmap (the one-digit hexadecimal
  177. values in the second column represent a color index for a single pixel):
  178.  
  179. Compressed data         Expanded data
  180.  
  181. 03 04                   0 4 0
  182. 05 06                   0 6 0 6 0 
  183. 00 06 45 56 67 00       4 5 5 6 6 7 
  184. 04 78                   7 8 7 8 
  185. 00 02 05 01             Move 5 right and 1 down 
  186. 04 78                   7 8 7 8 
  187. 00 00                   End of line 
  188. 09 1E                   1 E 1 E 1 E 1 E 1 
  189. 00 01                   End of RLE bitmap 
  190.  
  191. Bitmap Example
  192.  
  193. The following example is a text dump of a 16-color bitmap (4 bits per pixel):
  194.  
  195. Win3DIBFile
  196.               BitmapFileHeader
  197.                   Type       19778
  198.                   Size       3118
  199.                   Reserved1  0
  200.                   Reserved2  0
  201.                   OffsetBits 118
  202.               BitmapInfoHeader
  203.                   Size            40
  204.                   Width           80
  205.                   Height          75
  206.                   Planes          1
  207.                   BitCount        4
  208.                   Compression     0
  209.                   SizeImage       3000
  210.  
  211.                   XPelsPerMeter   0
  212.                   YPelsPerMeter   0
  213.                   ColorsUsed      16
  214.                   ColorsImportant 16
  215.               Win3ColorTable
  216.                   Blue  Green  Red  Unused
  217. [00000000]        84    252    84   0
  218. [00000001]        252   252    84   0
  219. [00000002]        84    84     252  0
  220. [00000003]        252   84     252  0
  221. [00000004]        84    252    252  0
  222. [00000005]        252   252    252  0
  223. [00000006]        0     0      0    0
  224. [00000007]        168   0      0    0
  225. [00000008]        0     168    0    0
  226. [00000009]        168   168    0    0
  227. [0000000A]        0     0      168  0
  228. [0000000B]        168   0      168  0
  229. [0000000C]        0     168    168  0
  230. [0000000D]        168   168    168  0
  231. [0000000E]        84    84     84   0
  232. [0000000F]        252   84     84   0
  233.               Image
  234.     .
  235.     .                                           Bitmap data
  236.     .
  237.  
  238. Icon-Resource File Format
  239.  
  240. An icon-resource file contains image data for icons used by Windows
  241. applications. The file consists of an icon directory identifying the number
  242. and types of icon images in the file, plus one or more icon images. The
  243. default filename extension for an icon-resource file is .ICO.
  244.  
  245. Icon Directory
  246.  
  247. Each icon-resource file starts with an icon directory. The icon directory,
  248. defined as an ICONDIR structure, specifies the number of icons in the
  249. resource and the dimensions and color format of each icon image. The ICONDIR
  250. structure has the following form:
  251.  
  252.  
  253.  
  254. typedef struct ICONDIR {
  255.     WORD          idReserved;
  256.     WORD          idType;
  257.     WORD          idCount;
  258.     ICONDIRENTRY  idEntries[1];
  259. } ICONHEADER;
  260.  
  261. Following are the members in the ICONDIR structure:
  262.  
  263. idReserved      Reserved; must be zero. 
  264. idType          Specifies the resource type. This member is set to 1. 
  265. idCount         Specifies the number of entries in the directory. 
  266. idEntries       Specifies an array of ICONDIRENTRY structures containing
  267. information about individual icons. The idCount member specifies the number
  268. of structures in the array.
  269.  
  270. The ICONDIRENTRY structure specifies the dimensions and color format for an
  271. icon. The structure has the following form:
  272.  
  273.  
  274.  
  275. struct IconDirectoryEntry {
  276.     BYTE  bWidth;
  277.     BYTE  bHeight;
  278.     BYTE  bColorCount;
  279.     BYTE  bReserved;
  280.     WORD  wPlanes;
  281.     WORD  wBitCount;
  282.     DWORD dwBytesInRes;
  283.     DWORD dwImageOffset;
  284. };
  285.  
  286. Following are the members in the ICONDIRENTRY structure: 
  287.  
  288. bWidth          Specifies the width of the icon, in pixels. Acceptable values
  289. are 16, 32, and 64.
  290.  
  291. bHeight         Specifies the height of the icon, in pixels. Acceptable
  292. values are 16, 32, and 64.
  293.  
  294. bColorCount     Specifies the number of colors in the icon. Acceptable values
  295. are 2, 8, and 16.
  296.  
  297. bReserved       Reserved; must be zero. 
  298. wPlanes         Specifies the number of color planes in the icon bitmap. 
  299. wBitCount       Specifies the number of bits in the icon bitmap. 
  300. dwBytesInRes    Specifies the size of the resource, in bytes. 
  301. dwImageOffset   Specifies the offset, in bytes, from the beginning of the
  302. file to the icon image.
  303.  
  304. Icon Image
  305.  
  306. Each icon-resource file contains one icon image for each image identified in
  307. the icon directory. An icon image consists of an icon-image header, a color
  308. table, an XOR mask, and an AND mask. The icon image has the following form:
  309.  
  310.  
  311.  
  312. BITMAPINFOHEADER    icHeader;
  313. RGBQUAD             icColors[];
  314. BYTE                icXOR[];
  315. BYTE                icAND[];
  316.  
  317. The icon-image header, defined as a BITMAPINFOHEADER structure, specifies the
  318. dimensions and color format of the icon bitmap. Only the biSize through
  319. biBitCount members and the biSizeImage member are used. All other members
  320. (such as biCompression and biClrImportant) must be set to zero.
  321.  
  322. The color table, defined as an array of RGBQUAD structures, specifies the
  323. colors used in the XOR mask. As with the color table in a bitmap file, the
  324. biBitCount member in the icon-image header determines the number of elements
  325. in the array. For more information about the color table, see Section 1.1,
  326. "Bitmap-File Formats."
  327.  
  328. The XOR mask, immediately following the color table, is an array of BYTE
  329. values representing consecutive rows of a bitmap. The bitmap defines the
  330. basic shape and color of the icon image. As with the bitmap bits in a bitmap
  331. file, the bitmap data in an icon-resource file is organized in scan lines,
  332. with each byte representing one or more pixels, as defined by the color
  333. format. For more information about these bitmap bits, see Section 1.1,
  334. "Bitmap-File Formats."
  335.  
  336. The AND mask, immediately following the XOR mask, is an array of BYTE values,
  337. representing a monochrome bitmap with the same width and height as the XOR
  338. mask. The array is organized in scan lines, with each byte representing 8
  339. pixels.
  340.  
  341. When Windows draws an icon, it uses the AND and XOR masks to combine the icon
  342. image with the pixels already on the display surface. Windows first applies
  343. the AND mask by using a bitwise AND operation; this preserves or removes
  344. existing pixel color.  Windows then applies the XOR mask by using a bitwise
  345. XOR operation. This sets the final color for each pixel.
  346.  
  347. The following illustration shows the XOR and AND masks that create a
  348. monochrome icon (measuring 8 pixels by 8 pixels) in the form of an uppercase
  349. K:
  350.  
  351. Windows Icon Selection
  352.  
  353. Windows detects the resolution of the current display and matches it against
  354. the width and height specified for each version of the icon image. If Windows
  355. determines that there is an exact match between an icon image and the current
  356. device, it uses the matching image. Otherwise, it selects the closest match
  357. and stretches the image to the proper size.
  358.  
  359. If an icon-resource file contains more than one image for a particular
  360. resolution, Windows uses the icon image that most closely matches the color
  361. capabilities of the current display. If no image matches the device
  362. capabilities exactly, Windows selects the image that has the greatest number
  363. of colors without exceeding the number of display colors. If all images
  364. exceed the color capabilities of the current display, Windows uses the icon
  365. image with the least number of colors.
  366.  
  367.  
  368.  
  369. Cursor-Resource File Format
  370.  
  371. A cursor-resource file contains image data for cursors used by Windows
  372. applications. The file consists of a cursor directory identifying the number
  373. and types of cursor images in the file, plus one or more cursor images. The
  374. default filename extension for a cursor-resource file is .CUR.
  375.  
  376. Cursor Directory
  377.  
  378. Each cursor-resource file starts with a cursor directory. The cursor
  379. directory, defined as a CURSORDIR structure, specifies the number of cursors
  380. in the file and the dimensions and color format of each cursor image. The
  381. CURSORDIR structure has the following form:
  382.  
  383.  
  384. typedef struct _CURSORDIR {
  385.     WORD           cdReserved;
  386.     WORD           cdType;
  387.     WORD           cdCount;
  388.     CURSORDIRENTRY cdEntries[];
  389. } CURSORDIR;
  390.  
  391. Following are the members in the CURSORDIR structure: 
  392.  
  393. cdReserved      Reserved; must be zero. 
  394. cdType          Specifies the resource type. This member must be set to 2. 
  395. cdCount         Specifies the number of cursors in the file. 
  396. cdEntries       Specifies an array of CURSORDIRENTRY structures containing
  397. information about individual cursors. The cdCount member specifies the number
  398. of structures in the array.
  399.  
  400. A CURSORDIRENTRY structure specifies the dimensions and color format of a
  401. cursor image. The structure has the following form:
  402.  
  403.  
  404.  
  405. typedef struct _CURSORDIRENTRY {
  406.     BYTE  bWidth;
  407.     BYTE  bHeight;
  408.     BYTE  bColorCount;
  409.     BYTE  bReserved;
  410.     WORD  wXHotspot;
  411.     WORD  wYHotspot;
  412.     DWORD lBytesInRes;
  413.     DWORD dwImageOffset;
  414. } CURSORDIRENTRY;
  415.  
  416. Following are the members in the CURSORDIRENTRY structure: 
  417.  
  418. bWidth          Specifies the width of the cursor, in pixels. 
  419. bHeight         Specifies the height of the cursor, in pixels. 
  420. bColorCount     Reserved; must be zero. 
  421. bReserved       Reserved; must be zero.
  422. wXHotspot       Specifies the x-coordinate, in pixels, of the hot spot. 
  423. wYHotspot       Specifies the y-coordinate, in pixels, of the hot spot. 
  424. lBytesInRes     Specifies the size of the resource, in bytes. 
  425. dwImageOffset   Specifies the offset, in bytes, from the start of the file to
  426. the cursor image.
  427.  
  428. Cursor Image
  429.  
  430. Each cursor-resource file contains one cursor image for each image identified
  431. in the cursor directory. A cursor image consists of a cursor-image header, a
  432. color table, an XOR mask, and an AND mask. The cursor image has the following
  433. form:
  434.  
  435.  
  436.  
  437. BITMAPINFOHEADER    crHeader;
  438. RGBQUAD             crColors[];
  439. BYTE                crXOR[];
  440. BYTE                crAND[];
  441.  
  442. The cursor hot spot is a single pixel in the cursor bitmap that Windows uses
  443. to track the cursor. The crXHotspot and crYHotspot members specify the x- and
  444. y-coordinates of the cursor hot spot. These coordinates are 16-bit integers.
  445.  
  446. The cursor-image header, defined as a BITMAPINFOHEADER structure, specifies
  447. the dimensions and color format of the cursor bitmap. Only the biSize through
  448. biBitCount members and the biSizeImage member are used. The biHeight member
  449. specifies the combined height of the XOR and AND masks for the cursor. This
  450. value is twice the height of the XOR mask. The biPlanes and biBitCount
  451. members must be 1. All other members (such as biCompression and
  452. biClrImportant) must be set to zero.
  453.  
  454. The color table, defined as an array of RGBQUAD structures, specifies the
  455. colors used in the XOR mask. For a cursor image, the table contains exactly
  456. two structures, since the biBitCount member in the cursor-image header is
  457. always 1.
  458.  
  459. The XOR mask, immediately following the color table, is an array of BYTE
  460. values representing consecutive rows of a bitmap. The bitmap defines the
  461. basic shape and color of the cursor image. As with the bitmap bits in a
  462. bitmap file, the bitmap data in a cursor-resource file is organized in scan
  463. lines, with each byte representing one or more pixels, as defined by the
  464. color format. For more information about these bitmap bits, see Section 1.1,
  465. "Bitmap-File Formats."
  466.  
  467. The AND mask, immediately following the XOR mask, is an array of BYTE values
  468. representing a monochrome bitmap with the same width and height as the XOR
  469. mask. The array is organized in scan lines, with each byte representing 8
  470. pixels.
  471.  
  472. When Windows draws a cursor, it uses the AND and XOR masks to combine the
  473. cursor image with the pixels already on the display surface. Windows first
  474. applies the AND mask by using a bitwise AND operation; this preserves or
  475. removes existing pixel color.  Window then applies the XOR mask by using a
  476. bitwise XOR operation. This sets the final color for each pixel.
  477.  
  478. The following illustration shows the XOR and the AND masks that create a
  479. cursor (measuring 8 pixels by 8 pixels) in the form of an arrow:
  480.  
  481. Following are the bit-mask values necessary to produce black, white,
  482. inverted, and transparent results:
  483.  
  484. Pixel result    AND maskXOR mask
  485.  
  486. Black           0               0 
  487. White           0               1 
  488. Transparent     1               0 
  489. Inverted1               1 
  490.  
  491. Windows Cursor Selection
  492.  
  493. If a cursor-resource file contains more than one cursor image, Windows
  494. determines the best match for a particular display by examining the width and
  495. height of the cursor images.
  496.  
  497.  
  498. ==============================================================================
  499.  
  500.  
  501. BITMAPFILEHEADER (3.0)
  502.  
  503.  
  504.  
  505. typedef struct tagBITMAPFILEHEADER {    /* bmfh */
  506.     UINT    bfType;
  507.     DWORD   bfSize;
  508.     UINT    bfReserved1;
  509.     UINT    bfReserved2;
  510.     DWORD   bfOffBits;
  511. } BITMAPFILEHEADER;
  512.  
  513. The BITMAPFILEHEADER structure contains information about the type, size, and
  514. layout of a device-independent bitmap (DIB) file.
  515.  
  516. Member          Description
  517.  
  518. bfType          Specifies the type of file. This member must be BM. 
  519. bfSize          Specifies the size of the file, in bytes. 
  520. bfReserved1     Reserved; must be set to zero. 
  521. bfReserved2     Reserved; must be set to zero.
  522. bfOffBits       Specifies the byte offset from the BITMAPFILEHEADER structure
  523. to the actual bitmap data in the file.
  524.  
  525. Comments
  526.  
  527. A BITMAPINFO or BITMAPCOREINFO structure immediately follows the
  528. BITMAPFILEHEADER structure in the DIB file.
  529.  
  530. See Also
  531.  
  532. BITMAPCOREINFO, BITMAPINFO 
  533.  
  534.  
  535. ==============================================================================
  536. BITMAPINFO (3.0)
  537.  
  538.  
  539.  
  540. typedef struct tagBITMAPINFO {  /* bmi */
  541.     BITMAPINFOHEADER    bmiHeader;
  542.     RGBQUAD             bmiColors[1];
  543. } BITMAPINFO;
  544.  
  545. The BITMAPINFO structure fully defines the dimensions and color information
  546. for a Windows 3.0 or later device-independent bitmap (DIB).
  547.  
  548. Member          Description
  549.  
  550. bmiHeader       Specifies a BITMAPINFOHEADER structure that contains
  551. information about the dimensions and color format of a DIB.
  552.  
  553. bmiColors       Specifies an array of RGBQUAD structures that define the
  554. colors in the bitmap.
  555.  
  556. Comments
  557.  
  558. A Windows 3.0 or later DIB consists of two distinct parts: a BITMAPINFO
  559. structure, which describes the dimensions and colors of the bitmap, and an
  560. array of bytes defining the pixels of the bitmap. The bits in the array are
  561. packed together, but each scan line must be zero-padded to end on a LONG
  562. boundary. Segment boundaries, however, can appear anywhere in the bitmap. The
  563. origin of the bitmap is the lower-left corner.
  564.  
  565. The biBitCount member of the BITMAPINFOHEADER structure determines the number
  566. of bits which define each pixel and the maximum number of colors in the
  567. bitmap. This member may be set to any of the following values:
  568.  
  569. Value   Meaning
  570.  
  571. 1       The bitmap is monochrome, and the bmciColors member must contain two
  572. entries. Each bit in the bitmap array represents a pixel. If the bit is
  573. clear, the pixel is displayed with the color of the first entry in the
  574. bmciColors table. If the bit is set, the pixel has the color of the second
  575. entry in the table.
  576.  
  577. 4       The bitmap has a maximum of 16 colors, and the bmciColors member
  578. contains 16 entries. Each pixel in the bitmap is represented by a four-bit
  579. index into the color table.
  580.  
  581. For example, if the first byte in the bitmap is 0x1F, the byte represents two
  582. pixels. The first pixel contains the color in the second table entry, and the
  583. second pixel contains the color in the sixteenth table entry.
  584.  
  585. 8       The bitmap has a maximum of 256 colors, and the bmciColors member
  586. contains 256 entries. In this case, each byte in the array represents a
  587. single pixel.
  588.  
  589. 24      The bitmap has a maximum of 2^24 colors. The bmciColors member is
  590. NULL, and each 3-byte sequence in the bitmap array represents the relative
  591. intensities of red, green, and blue, respectively, of a pixel.
  592.  
  593. The biClrUsed member of the BITMAPINFOHEADER structure specifies the number
  594. of color indexes in the color table actually used by the bitmap. If the
  595. biClrUsed member is set to zero, the bitmap uses the maximum number of colors
  596. corresponding to the value of the biBitCount member.
  597.  
  598. The colors in the bmiColors table should appear in order of importance.
  599. Alternatively, for functions that use DIBs, the bmiColors member can be an
  600. array of 16-bit unsigned integers that specify an index into the currently
  601. realized logical palette instead of explicit RGB values. In this case, an
  602. application using the bitmap must call DIB functions with the wUsage
  603. parameter set to DIB_PAL_COLORS.
  604.  
  605. Note:   The bmiColors member should not contain palette indexes if the bitmap
  606. is to be stored in a file or transferred to another application. Unless the
  607. application uses the bitmap exclusively and under its complete control, the
  608. bitmap color table should contain explicit RGB values.
  609.  
  610. See Also
  611.  
  612. BITMAPINFOHEADER, RGBQUAD 
  613.  
  614. ==============================================================================
  615. BITMAPINFOHEADER (3.0)
  616.  
  617.  
  618.  
  619. typedef struct tagBITMAPINFOHEADER {    /* bmih */
  620.     DWORD   biSize;
  621.     LONG    biWidth;
  622.     LONG    biHeight;
  623.     WORD    biPlanes;
  624.     WORD    biBitCount;
  625.     DWORD   biCompression;
  626.     DWORD   biSizeImage;
  627.     LONG    biXPelsPerMeter;
  628.     LONG    biYPelsPerMeter;
  629.     DWORD   biClrUsed;
  630.     DWORD   biClrImportant;
  631. } BITMAPINFOHEADER;
  632.  
  633. The BITMAPINFOHEADER structure contains information about the dimensions and
  634. color format of a Windows 3.0 or later device-independent bitmap (DIB).
  635.  
  636. Member          Description
  637.  
  638. biSize          Specifies the number of bytes required by the
  639. BITMAPINFOHEADER structure.
  640.  
  641. biWidth         Specifies the width of the bitmap, in pixels. 
  642. biHeightSpecifies the height of the bitmap, in pixels. 
  643.  
  644. biPlanesSpecifies the number of planes for the target device. This
  645. member must be set to 1.
  646.  
  647. biBitCount      Specifies the number of bits per pixel. This value must be 1,
  648. 4, 8, or 24.
  649.  
  650. biCompression   Specifies the type of compression for a compressed bitmap. It
  651. can be one of the following values:
  652.  
  653. Value           Meaning
  654.  
  655. BI_RGB          Specifies that the bitmap is not compressed. 
  656.  
  657. BI_RLE8         Specifies a run-length encoded format for bitmaps with 8 bits
  658. per pixel. The compression format is a 2-byte format consisting of a count
  659. byte followed by a byte containing a color index.  For more information, see
  660. the following Comments section.
  661.  
  662. BI_RLE4         Specifies a run-length encoded format for bitmaps with 4 bits
  663. per pixel. The compression format is a 2-byte format consisting of a count
  664. byte followed by two word-length color indexes.  For more information, see
  665. the following Comments section.
  666.  
  667. biSizeImage     Specifies the size, in bytes, of the image. It is valid to
  668. set this member to zero if the bitmap is in the BI_RGB format.
  669.  
  670. biXPelsPerMeter Specifies the horizontal resolution, in pixels per meter, of
  671. the target device for the bitmap. An application can use this value to select
  672. a bitmap from a resource group that best matches the characteristics of the
  673. current device.
  674.  
  675. biYPelsPerMeter Specifies the vertical resolution, in pixels per meter, of
  676. the target device for the bitmap.
  677.  
  678. biClrUsed       Specifies the number of color indexes in the color table
  679. actually used by the bitmap. If this value is zero, the bitmap uses the
  680. maximum number of colors corresponding to the value of the biBitCount member.
  681. For more information on the maximum sizes of the color table, see the
  682. description of the BITMAPINFO structure earlier in this topic.
  683.  
  684. If the biClrUsed member is nonzero, it specifies the actual number of colors
  685. that the graphics engine or device driver will access if the biBitCount
  686. member is less than 24. If biBitCount is set to 24, biClrUsed specifies the
  687. size of the reference color table used to optimize performance of Windows
  688. color palettes.  If the bitmap is a packed bitmap (that is, a bitmap in which
  689. the bitmap array immediately follows the BITMAPINFO header and which is
  690. referenced by a single pointer), the biClrUsed member must be set to zero or
  691. to the actual size of the color table.
  692.  
  693. biClrImportant  Specifies the number of color indexes that are considered
  694. important for displaying the bitmap. If this value is zero, all colors are
  695. important.
  696.  
  697. Comments
  698.  
  699. The BITMAPINFO structure combines the BITMAPINFOHEADER structure and a color
  700. table to provide a complete definition of the dimensions and colors of a
  701. Windows 3.0 or later DIB. For more information about specifying a Windows 3.0
  702. DIB, see the description of the BITMAPINFO structure.
  703.  
  704. An application should use the information stored in the biSize member to
  705. locate the color table in a BITMAPINFO structure as follows:
  706.  
  707. pColor = ((LPSTR) pBitmapInfo + (WORD) (pBitmapInfo->bmiHeader.biSize))
  708.  
  709. Windows supports formats for compressing bitmaps that define their colors
  710. with 8 bits per pixel and with 4 bits per pixel. Compression reduces the disk
  711. and memory storage required for the bitmap. The following paragraphs describe
  712. these formats.
  713.  
  714. BI_RLE8
  715.  
  716. When the biCompression member is set to BI_RLE8, the bitmap is compressed
  717. using a run-length encoding format for an 8-bit bitmap. This format may be
  718. compressed in either of two modes: encoded and absolute. Both modes can occur
  719. anywhere throughout a single bitmap.
  720.  
  721. Encoded mode consists of two bytes: the first byte specifies the number of
  722. consecutive pixels to be drawn using the color index contained in the second
  723. byte. In addition, the first byte of the pair can be set to zero to indicate
  724. an escape that denotes an end of line, end of bitmap, or a delta. The
  725. interpretation of the escape depends on the value of the second byte of the
  726. pair. The following list shows the meaning of the second byte:
  727.  
  728. Value   Meaning
  729.  
  730. 0       End of line. 
  731. 1       End of bitmap. 
  732. 2       Delta. The two bytes following the escape contain unsigned values
  733. indicating the horizontal and vertical offset of the next pixel from the
  734. current position.
  735.  
  736. Absolute mode is signaled by the first byte set to zero and the second byte
  737. set to a value between 0x03 and 0xFF. In absolute mode, the second byte
  738. represents the number of bytes that follow, each of which contains the color
  739. index of a single pixel. When the second byte is set to 2 or less, the escape
  740. has the same meaning as in encoded mode. In absolute mode, each run must be
  741. aligned on a word boundary.  The following example shows the hexadecimal
  742. values of an 8-bit compressed bitmap:
  743.  
  744.  
  745.  
  746. 03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01
  747. 02 78 00 00 09 1E 00 01
  748.  
  749. This bitmap would expand as follows (two-digit values represent a color index
  750. for a single pixel):
  751.  
  752.  
  753.  
  754. 04 04 04
  755. 06 06 06 06 06
  756. 45 56 67
  757. 78 78
  758. move current position 5 right and 1 down
  759. 78 78
  760. end of line
  761. 1E 1E 1E 1E 1E 1E 1E 1E 1E
  762. end of RLE bitmap
  763.  
  764. BI_RLE4
  765.  
  766. When the biCompression member is set to BI_RLE4, the bitmap is compressed
  767. using a run-length encoding (RLE) format for a 4-bit bitmap, which also uses
  768. encoded and absolute modes. In encoded mode, the first byte of the pair
  769. contains the number of pixels to be drawn using the color indexes in the
  770. second byte. The second byte contains two color indexes, one in its
  771. high-order nibble (that is, its low-order four bits) and one in its low-order
  772. nibble. The first of the pixels is drawn using the color specified by the
  773. high-order nibble, the second is drawn using the color in the low-order
  774. nibble, the third is drawn with the color in the high-order nibble, and so
  775. on, until all the pixels specified by the first byte have been drawn.  In
  776. absolute mode, the first byte contains zero, the second byte contains the
  777. number of color indexes that follow, and subsequent bytes contain color
  778. indexes in their high- and low-order nibbles, one color index for each pixel.
  779. In absolute mode, each run must be aligned on a word boundary. The
  780. end-of-line, end-of-bitmap, and delta escapes also apply to BI_RLE4.
  781.  
  782. The following example shows the hexadecimal values of a 4-bit compressed
  783. bitmap:
  784.  
  785.  
  786.  
  787. 03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01
  788. 04 78 00 00 09 1E 00 01
  789.  
  790. This bitmap would expand as follows (single-digit values represent a color
  791. index for a single pixel):
  792.  
  793.  
  794.  
  795. 0 4 0
  796. 0 6 0 6 0
  797. 4 5 5 6 6 7
  798. 7 8 7 8
  799. move current position 5 right and 1 down
  800. 7 8 7 8
  801. end of line
  802. 1 E 1 E 1 E 1 E 1
  803. end of RLE bitmap
  804.  
  805. See Also
  806.  
  807. BITMAPINFO 
  808.  
  809. ==============================================================================
  810. RGBQUAD (3.0)
  811.  
  812.  
  813.  
  814. typedef struct tagRGBQUAD {     /* rgbq */
  815.     BYTE    rgbBlue;
  816.     BYTE    rgbGreen;
  817.     BYTE    rgbRed;
  818.     BYTE    rgbReserved;
  819. } RGBQUAD;
  820.  
  821. The RGBQUAD structure describes a color consisting of relative intensities of
  822. red, green, and blue. The bmiColors member of the BITMAPINFO structure
  823. consists of an array of RGBQUAD structures.
  824.  
  825. Member          Description
  826.  
  827. rgbBlue         Specifies the intensity of blue in the color. 
  828. rgbGreenSpecifies the intensity of green in the color. 
  829. rgbRed          Specifies the intensity of red in the color. 
  830. rgbReserved     Not used; must be set to zero. 
  831.  
  832. See Also
  833.  
  834. BITMAPINFO 
  835.  
  836. ==============================================================================
  837. RGB (2.x)
  838.  
  839. COLORREF RGB(cRed, cGreen, cBlue)
  840.  
  841. BYTE cRed;      /* red component of color       */
  842. BYTE cGreen;    /* green component of color     */
  843. BYTE cBlue;     /* blue component of color      */
  844.  
  845.  
  846. The RGB macro selects an RGB color based on the parameters supplied and the
  847. color capabilities of the output device.
  848.  
  849. Parameter       Description
  850.  
  851. cRed    Specifies the intensity of the red color field. 
  852. cGreen  Specifies the intensity of the green color field. 
  853. cBlue   Specifies the intensity of the blue color field. 
  854.  
  855. Returns
  856.  
  857. The return value specifies the resultant RGB color. 
  858.  
  859. Comments
  860.  
  861. The intensity for each argument can range from 0 through 255. If all three
  862. intensities are specified as zero, the result is black. If all three
  863. intensities are specified as 255, the result is white.
  864.  
  865. Comments
  866.  
  867. The RGB macro is defined in WINDOWS.H as follows: 
  868.  
  869.  
  870.  
  871. #define RGB(r,g,b)   ((COLORREF)(((BYTE)(r)|((WORD)(g)<<8))| \
  872.     (((DWORD)(BYTE)(b))<<16)))
  873.  
  874. See Also
  875.  
  876. GetBValue, GetGValue, GetRValue, PALETTEINDEX, PALETTERGB
  877.  
  878. ==============================================================================
  879. BITMAPCOREINFO (3.0)
  880.  
  881.  
  882.  
  883. typedef struct tagBITMAPCOREINFO {  /* bmci */
  884.     BITMAPCOREHEADER bmciHeader;
  885.     RGBTRIPLE        bmciColors[1];
  886. } BITMAPCOREINFO;
  887.  
  888. The BITMAPCOREINFO structure fully defines the dimensions and color
  889. information for a device-independent bitmap (DIB).  Windows applications
  890. should use the BITMAPINFO structure instead of BITMAPCOREINFO whenever
  891. possible.
  892.  
  893. Member          Description
  894.  
  895. bmciHeader      Specifies a BITMAPCOREHEADER structure that contains
  896. information about the dimensions and color format of a DIB.
  897.  
  898. bmciColors      Specifies an array of RGBTRIPLE structures that define the
  899. colors in the bitmap.
  900.  
  901. Comments
  902.  
  903. The BITMAPCOREINFO structure describes the dimensions and colors of a bitmap.
  904. It is followed immediately in memory by an array of bytes which define the
  905. pixels of the bitmap. The bits in the array are packed together, but each
  906. scan line must be zero-padded to end on a LONG boundary. Segment boundaries,
  907. however, can appear anywhere in the bitmap. The origin of the bitmap is the
  908. lower-left corner.
  909.  
  910. The bcBitCount member of the BITMAPCOREHEADER structure determines the number
  911. of bits that define each pixel and the maximum number of colors in the
  912. bitmap. This member may be set to any of the following values:
  913.  
  914. Value   Meaning
  915.  
  916. 1       The bitmap is monochrome, and the bmciColors member must contain two
  917. entries. Each bit in the bitmap array represents a pixel. If the bit is
  918. clear, the pixel is displayed with the color of the first entry in the
  919. bmciColors table. If the bit is set, the pixel has the color of the second
  920. entry in the table.
  921.  
  922. 4       The bitmap has a maximum of 16 colors, and the bmciColors member
  923. contains 16 entries. Each pixel in the bitmap is represented by a four-bit
  924. index into the color table.
  925.  
  926. For example, if the first byte in the bitmap is 0x1F, the byte represents two
  927. pixels. The first pixel contains the color in the second table entry, and the
  928. second pixel contains the color in the sixteenth table entry.
  929.  
  930. 8       The bitmap has a maximum of 256 colors, and the bmciColors member
  931. contains 256 entries. In this case, each byte in the array represents a
  932. single pixel.
  933.  
  934. 24      The bitmap has a maximum of 2^24 colors. The bmciColors member is
  935. NULL, and each 3-byte sequence in the bitmap array represents the relative
  936. intensities of red, green, and blue, respectively, of a pixel.
  937.  
  938. The colors in the bmciColors table should appear in order of importance.
  939. Alternatively, for functions that use DIBs, the bmciColors member can be an
  940. array of 16-bit unsigned integers that specify an index into the currently
  941. realized logical palette instead of explicit RGB values. In this case, an
  942. application using the bitmap must call DIB functions with the wUsage
  943. parameter set to DIB_PAL_COLORS.
  944.  
  945. Note:   The bmciColors member should not contain palette indexes if the
  946. bitmap is to be stored in a file or transferred to another application.
  947. Unless the application uses the bitmap exclusively and under its complete
  948. control, the bitmap color table should contain explicit RGB values.
  949.  
  950. See Also
  951.  
  952. BITMAPINFO, BITMAPCOREHEADER, RGBTRIPLE 
  953.  
  954.  
  955. ==============================================================================
  956. BITMAPCOREHEADER (3.0)
  957.  
  958.  
  959.  
  960. typedef struct tagBITMAPCOREHEADER {    /* bmch */
  961.     DWORD   bcSize;
  962.     short   bcWidth;
  963.     short   bcHeight;
  964.     WORD    bcPlanes;
  965.     WORD    bcBitCount;
  966. } BITMAPCOREHEADER;
  967.  
  968. The BITMAPCOREHEADER structure contains information about the dimensions and
  969. color format of a device-independent bitmap (DIB). Windows applications
  970. should use the BITMAPINFOHEADER structure instead of BITMAPCOREHEADER
  971. whenever possible.
  972.  
  973. Member          Description
  974.  
  975. bcSize          Specifies the number of bytes required by the
  976. BITMAPCOREHEADER structure.
  977.  
  978. bcWidth         Specifies the width of the bitmap, in pixels. 
  979. bcHeightSpecifies the height of the bitmap, in pixels. 
  980.  
  981. bcPlanesSpecifies the number of planes for the target device. This
  982. member must be set to 1.
  983.  
  984. bcBitCount      Specifies the number of bits per pixel. This value must be 1,
  985. 4, 8, or 24.
  986.  
  987. Comments
  988.  
  989. The BITMAPCOREINFO structure combines the BITMAPCOREHEADER structure and a
  990. color table to provide a complete definition of the dimensions and colors of
  991. a DIB. See the description of the BITMAPCOREINFO structure for more
  992. information about specifying a DIB.
  993.  
  994. An application should use the information stored in the bcSize member to
  995. locate the color table in a BITMAPCOREINFO structure with a method such as
  996. the following:
  997.  
  998.  
  999.  
  1000. lpColor = ((LPSTR) pBitmapCoreInfo + (UINT) (pBitmapCoreInfo->bcSize))
  1001.  
  1002. See Also
  1003.  
  1004. BITMAPCOREINFO, BITMAPINFOHEADER, BITMAPINFOHEADER 
  1005.  
  1006. =============================================================================
  1007. RGBTRIPLE (3.0)
  1008.  
  1009.  
  1010.  
  1011. typedef struct tagRGBTRIPLE {   /* rgbt */
  1012.     BYTE    rgbtBlue;
  1013.     BYTE    rgbtGreen;
  1014.     BYTE    rgbtRed;
  1015. } RGBTRIPLE;
  1016.  
  1017. The RGBTRIPLE structure describes a color consisting of relative intensities
  1018. of red, green, and blue. The bmciColors member of the BITMAPCOREINFO
  1019. structure consists of an array of RGBTRIPLE structures.  Windows applications
  1020. should use the BITMAPINFO structure instead of BITMAPCOREINFO whenever
  1021. possible. The BITMAPINFO structure uses an RGBQUAD structure instead of the
  1022. RGBTRIPLE structure.
  1023.  
  1024. Member  Description
  1025.  
  1026. rgbtBlueSpecifies the intensity of blue in the color. 
  1027. rgbtGreen       Specifies the intensity of green in the color. 
  1028. rgbtRed         Specifies the intensity of red in the color.
  1029.  
  1030. See Also
  1031.  
  1032. BITMAPCOREINFO, BITMAPINFO, RGBQUAD
  1033.  
  1034. ==============================================================================
  1035.